<?php

/**
 * This is the model class for table "news".
 *
 * The followings are the available columns in table 'news':
 * @property integer $id
 * @property string $url
 * @property string $title
 * @property string $category
 * @property integer $day_rank
 * @property integer $week_rank
 * @property integer $month_rank
 * @property integer $whole_drank
 * @property integer $whole_wrank
 * @property integer $whole_mrank
 * @property string $time
 */
class News extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return News the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'news';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('url, title, category, day_rank, week_rank, month_rank, whole_drank, whole_wrank, whole_mrank, time', 'required'),
			array('day_rank, week_rank, month_rank, whole_drank, whole_wrank, whole_mrank', 'numerical', 'integerOnly'=>true),
			array('url, title', 'length', 'max'=>200),
			array('category', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, url, title, category, day_rank, week_rank, month_rank, whole_drank, whole_wrank, whole_mrank, time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'url' => 'Url',
			'title' => 'Title',
			'category' => 'Category',
			'day_rank' => 'Day Rank',
			'week_rank' => 'Week Rank',
			'month_rank' => 'Month Rank',
			'whole_drank' => 'Whole Drank',
			'whole_wrank' => 'Whole Wrank',
			'whole_mrank' => 'Whole Mrank',
			'time' => 'Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('url',$this->url,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('category',$this->category,true);
		$criteria->compare('day_rank',$this->day_rank);
		$criteria->compare('week_rank',$this->week_rank);
		$criteria->compare('month_rank',$this->month_rank);
		$criteria->compare('whole_drank',$this->whole_drank);
		$criteria->compare('whole_wrank',$this->whole_wrank);
		$criteria->compare('whole_mrank',$this->whole_mrank);
		$criteria->compare('time',$this->time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        protected function afterVaidate(){
            parent::afterValidate();
            $this->password=md5($this->password);
        }
}